# uncompyle6 version 3.2.3
# Python bytecode 3.6 (3379)
# Decompiled from: Python 3.6.8 |Anaconda custom (64-bit)| (default, Feb 21 2019, 18:30:04) [MSC v.1916 64 bit (AMD64)]
# Embedded file name: site-packages\PyInstaller\__main__.py
"""
Main command-line interface to PyInstaller.
"""
import os, argparse, platform, sys
from . import __version__
from . import log as logging
from .compat import check_requirements

logger = logging.getLogger(__name__)


def run_makespec(filenames, **opts):
    temppaths = opts["pathex"][:]
    pathex = opts["pathex"] = []
    for p in temppaths:
        pathex.extend(p.split(os.pathsep))

    import PyInstaller.building.makespec

    spec_file = PyInstaller.building.makespec.main(filenames, **opts)
    logger.info("wrote %s" % spec_file)
    return spec_file


def run_build(pyi_config, spec_file, **kwargs):
    import PyInstaller.building.build_main

    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)


def __add_options(parser):
    parser.add_argument(
        "-v",
        "--version",
        action="version",
        version=__version__,
        help="Show program version info and exit.",
    )


def run(pyi_args=None, pyi_config=None):
    """
    pyi_args     allows running PyInstaller programatically without a subprocess
    pyi_config   allows checking configuration once when running multiple tests
    """
    check_requirements()
    import PyInstaller.building.makespec, PyInstaller.building.build_main, PyInstaller.log

    try:
        parser = argparse.ArgumentParser()
        __add_options(parser)
        PyInstaller.building.makespec.__add_options(parser)
        PyInstaller.building.build_main.__add_options(parser)
        PyInstaller.log.__add_options(parser)
        parser.add_argument(
            "filenames",
            metavar="scriptname",
            nargs="+",
            help="name of scriptfiles to be processed or exactly one .spec-file. If a .spec-file is specified, most options are unnecessary and are ignored.",
        )
        args = parser.parse_args(pyi_args)
        PyInstaller.log.__process_options(parser, args)
        logger.info("PyInstaller: %s" % __version__)
        logger.info("Python: %s" % platform.python_version())
        logger.info("Platform: %s" % platform.platform())
        if args.filenames[0].endswith(".spec"):
            spec_file = args.filenames[0]
        else:
            spec_file = run_makespec(**vars(args))
        run_build(pyi_config, spec_file, **vars(args))
    except KeyboardInterrupt:
        raise SystemExit("Aborted by user request.")


if __name__ == "__main__":
    run()
